package com.shouhuobao.samecity;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.collectplus.express.R;
import com.collectplus.express.model.SameCityHistoryBean;
import com.shouhuobao.visit.VisitHistoryRecordActivity;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;
import droid.frame.utils.lang.Str;

/**
 * Created by lidandan on 2017/12/27.
 * 同城历史记录适配器
 */
public class SameCityAddressHistoryAdapter extends BaseAdapterExt<SameCityHistoryBean> {

    public SameCityAddressHistoryAdapter(ArrayList<SameCityHistoryBean> items, Activity context) {
        super(items, context);
        //空白显示
        if (context instanceof VisitHistoryRecordActivity) {
            setEmptyView(R.layout.visit_history_empty);
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_samecity_history, parent, false);
            holder.mAddressTv = (TextView) convertView.findViewById(R.id.address_tv);
            holder.mAddressDetailTv = (TextView) convertView.findViewById(R.id.address_detail_tv);
            holder.nameTV = (TextView) convertView.findViewById(R.id.name_tv);
            holder.phoneTV = (TextView) convertView.findViewById(R.id.phone_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SameCityHistoryBean bean = getItem(position);
        holder.mAddressTv.setText(bean.getBuildName());
        holder.mAddressDetailTv.setText(bean.getAddress());
        if (Str.isEmpty(bean.getUserName())) {
            holder.nameTV.setVisibility(View.INVISIBLE);
        } else {
            holder.nameTV.setVisibility(View.VISIBLE);
            holder.nameTV.setText(bean.getUserName());
        }
        if (Str.isEmpty(bean.getPhone())) {
            holder.phoneTV.setVisibility(View.INVISIBLE);
        } else {
            holder.phoneTV.setVisibility(View.VISIBLE);
            holder.phoneTV.setText(bean.getPhone());
        }
        return convertView;
    }

    class ViewHolder {
        TextView mAddressTv;
        TextView mAddressDetailTv;
        TextView nameTV;
        TextView phoneTV;
    }
}

